package fun.cyhgraph.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.github.pagehelper.Page;
import fun.cyhgraph.annotation.AutoFill;
import fun.cyhgraph.model.dto.CategoryTypePageDTO;
import fun.cyhgraph.model.entity.Category;
import fun.cyhgraph.enumeration.OperationType;
import fun.cyhgraph.model.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CategoryMapper extends BaseMapper<Category> {

    @Insert("insert into category (name, type, sort, status, create_user, update_user, create_time, update_time, merchant_id) VALUES " +
            "(#{category.name}, #{category.type}, #{category.sort}, #{category.status}, #{category.createUser}, #{category.updateUser}, #{category.createTime}, #{category.updateTime}, #{category.merchantId})")
    void add(@Param("category") Category category);
    Page<Category> getPageList(CategoryTypePageDTO categoryTypePageDTO);

    @Select("select * from category where id = #{id}")
    Category getById(Integer id);

    @AutoFill(OperationType.UPDATE)
    void update(Category category);

    @Delete("delete from category where id = #{id}")
    void delete(Integer id);

    @Update("update category set status = IF(status = 0, 1, 0) where id = #{id} and merchant_id = #{merchantId}")
    boolean  onOff(Integer id , Integer merchantId);

    /**
     * 根据type查询分类，没有就查所有，且只能查有启用的分类
     * @param type
     * @return
     */
    List<Category> getList(Integer type);
    @Delete("delete from category where id = #{id} and merchant_id = #{merchantId}")
    boolean deleteCategory(Integer id, Integer merchantId);
}
